<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%@ page session="false" contentType="text/html; charset=UTF-8"%>
<!DOCTYPE html>
<html>
<head>
	<title>수리 요청 조회</title>
	<style>
		div.dhxform_btn {
			height: 24px;
		}
	</style>
	
	<jsp:include page="/WEB-INF/views/common/header2.jsp"/>
	
	<script type="text/javascript" src= "<c:out value="${pageContext.request.contextPath}"/>/resources/js/popup/customer_popup.js"></script>
	<script type="text/javascript">
		//<![CDATA[
		var toolbar;
		var mainForm;
		var mainGrid;
		
		function doOnLoad() {
			// main.jsp 우측 layout progressOn
			toolbar = new dhtmlXToolbarObject({
				parent:'toolbar_div',
				icons_path: contextPath + "/resources/imgs/icons_terrace/"
			});
			
			toolbar.addButton("retrieve", 0, "조회", "", "");
			toolbar.addSeparator("sep1", 1);
			toolbar.addButton("new", 2, "신규", "", "");
			toolbar.addSeparator("sep2", 3);
			toolbar.addButton("excel", 4, "엑셀", "", "");
			toolbar.addSeparator("sep3", 5);
			toolbar.addButton("save_as", 6, "닫기", "", "");
			
			var formData = [
			            {type: "settings", position: "label-left", labelWidth: 120, inputWidth: 120},
			            {type: "fieldset", width:"100%", label:"고객", className:"clientBlock", 
			            	list: [
			            	       {type: "block", width:"100%", 
			            	    	   list:[
			            	    	         {type: "input", name: "customer_code", label: "고객", readonly: true},
			            	    	         {type: "newcolumn"},
			            	    	         {type: "input", name: "customer_name", readonly: true},
			            	    	         {type: "newcolumn"},
			            	    	         {type: "button", name: "customer_button", value: "선택"}
			            	    	         ]
			            	       },
			            	       {type: "block", width:"100%", 
			            	    	   list:[
			            	    	         {type: "input", name: "manager_code", label: "관리국", readonly: true},
			            	    	         {type: "newcolumn"},
			            	    	         {type: "input", name: "manager_name", readonly: true},
			            	    	         {type: "newcolumn"},
			            	    	         {type: "button", name: "manager_button", value: "선택"},
			            	    	         {type: "newcolumn", offset: 20},
			            	    	         {type: "input", name: "operator_code", label: "운용국", readonly: true},
			            	    	         {type: "newcolumn"},
			            	    	         {type: "input", name: "operator_name", readonly: true},
			            	    	         {type: "newcolumn"},
			            	    	         {type: "button", name: "operator_button", value: "선택"}
			            	    	         ]
			            	       }
			            	       ]
			            },
			            {type: "fieldset", width:"100%", label:"Repair Order", className:"orderBlock", 
			            	list: [
			            	       {type: "block", width:"100%", 
			            	    	   list:[
			            	    	         {type: "input", name: "serial_no", label: "Serial No", width:302},
			            	    	         {type: "newcolumn", offset: 20},
			            	    	         {type: "input", name: "repair_order_no", label: "Repair Order No", width:302}
			            	    	         ]
			            	       }
		            	       ]
			            },
			            {type: "block", width:"100%",
			            	list: [
			            	       {type: "newcolumn", offset:300},
			            	       {type: "button", name: "create_button", value: "Repair Order 작성", width: 120},
			            	       {type: "newcolumn"},
			            	       {type: "button", name: "clear_button", value: "지우기", width: 120},
			            	       {type: "newcolumn"},
			            	       {type: "button", name: "search_button", value: "찾기", width: 120}
			            	       ]
			            }
			           ];
			
			mainForm = new dhtmlXForm("form_div", formData);
			mainForm.attachEvent("onButtonClick", function(name) {
				if ( name == "customer_button" ) {
					showCustomer();
				}
				else if ( name == "manager_button" ) {
					showManager();
				}
				else if ( name == "operator_button" ) {
					showOperator();
				}
				else if ( name == "search_button" ) {
					retrieve();
				}
			});
			
			mainGrid = new dhtmlXGridObject("grid_div");
			mainGrid.setImagePath(contextPath + "/resources/common/dhtmlx/imgs/dhxgrid_terrace/");
			mainGrid.setHeader("No, Repair Order No, Serial No, 기종 Code, 품목, 수리의뢰일, 고객, 운용국, 고객조치상태, 고객 조치일, 고객 인계 확인일");
			mainGrid.setInitWidths("50,150,130,100,100,100,100,100,100,100,100");
			mainGrid.setColumnIds("rowNum,roHeaderId,serialNo,itemGroup,inventoryItemId,roRequestDate,custName,sheepCustomer,custShippingFlag,whDate,lastCustConfirmDate");
			//mainGrid.setPagingSkin("toolbar", "dhx_terrace");
			mainGrid.init();
			
			//parent.progressOff();
		};		
		
		function retrieve() {
			var accountNumber 	= mainForm.getItemValue('customer_code');
			var serialNo 		= mainForm.getItemValue('serial_no');
			var repairOrderNo	= mainForm.getItemValue('repair_order_no');
			/*
			if ( serialNo == null || serialNo.trim().length == 0 ) {
				alert("Serial No. 값은 필수입니다.");
				return;
			}
			*/
			$.ajax({
				url:contextPath + "/repair_order_retrieve",
				data:{accountNumber:accountNumber, serialNo:serialNo, orderNo:repairOrderNo},
				type:'GET',
				dataType:'json'
			}).done(function(data) {
				mainGrid.clearAll();
				mainGrid.parse(data, "js");
			});
		};		
		//]]
	</script>
</head>
<body onload="doOnLoad();">
	<div style="height: 40px;">
		<div id="toolbar_div"></div>
	</div>
	<div id="form_div" style="width: 100%;"></div>
	<div id="grid_div" style="width: 100%; height:200px"></div>	
</body>
</html>